#include <vector>
#include <string>
#include <iostream>
#include <cctype>
#include <algorithm>

/**
 * @brief 版本号比较
 *
 * @return ==0 相等, >0 left>right, <0 left<right
 */
int compare_versions(const std::vector<int>& left, const std::vector<int>& right) {
	size_t len = std::max(left.size(), right.size());

	for (size_t i = 0; i < len; ++i) {
		int left_value = (i < left.size()) ? left[i] : 0;
		int right_value = (i < right.size()) ? right[i] : 0;

		if (left_value < right_value) {
			return -1;
		} else if (left_value > right_value) {
			return 1;
		}
	}

	return 0;
}
std::vector<int> version_to_vector(const std::string& version) {
    std::vector<int> result;
    size_t start = 0, end;

    while ((end = version.find('.', start)) != std::string::npos) {
        std::string part = version.substr(start, end - start);
        if (!part.empty() && std::all_of(part.begin(), part.end(), ::isdigit)) {
            result.push_back(std::stoi(part));
        } else {
			result.push_back(0);
		}
        start = end + 1;
    }

    // Process the last part
    std::string last_part = version.substr(start);
    if (!last_part.empty() && std::all_of(last_part.begin(), last_part.end(), ::isdigit)) {
        result.push_back(std::stoi(last_part));
    } else {
		result.push_back(0);
	}

    return result;
}

int main() {
    std::vector<std::string> test_versions = {
        "1.1.1.1",
        "1.1.1.1.",
        "1.2a.3.4",
        "1..2.3",
        "",
        "123",
        "001.002.003"
    };

    for (const auto& version : test_versions) {
        std::vector<int> version_vector = version_to_vector(version);
        std::cout << "Version string: " << version << " -> [ ";
        for (int number : version_vector) {
            std::cout << number << " ";
        }
        std::cout << "]" << std::endl;
    }

    return 0;
}
